local skill = fk.CreateSkill{
  name = "action__quanjie_skill",
}

Fk:loadTranslationTable{
  ["action__quanjie"] = "劝酒",
  ["action__quanjie_skill"] = "劝酒",
  [":action__quanjie"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：令所有角色的手牌随机变成【酒】直到回合结束并从你的下家开始依次打出【酒】，最后不打出【酒】的角色受到每名其他角色造成的一点伤害。（不可响应）",
  ["#action__quanjie_skill"] = "令所有角色的手牌随机变成【酒】直到回合结束并从你的下家开始依次打出【酒】，最后不打出【酒】的角色受到每名其他角色造成的一点伤害",
  ["@action__quanjie-phase"] = "微醺",
}


skill:addEffect("cardskill", {
  mute = true,
  name = "action__quanjie",
  prompt = "#action__quanjie_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local respond
    for _, p in ipairs(room:getAlivePlayers()) do
      local cards = p:getCardIds(Player.Hand)
      for _, id in ipairs(cards) do
        local card = Fk:getCardById(id)
        if card.name ~= "analeptic" or card:getMark("action__quanjie-turn") == 0 then
          if math.random(2) == 1 then
            room:addCardMark(card, "action__quanjie-turn", 1)
          end
        end
      end
    end
    local shouldBreak = 2
    for i = 1, 99 do
      local targets
      if i == 1 then
        targets = room:getOtherPlayers(effect.to)
      else
        targets = room:getAlivePlayers()
      end
      for _, p in ipairs(targets) do
        respond = room:askToResponse(p, {
          skill_name = "action__quanjie_skill",
          pattern = "analeptic",
          cancelable = true,
        })
        if respond then
          room:responseCard(respond)
          room:addPlayerMark(p, "@action__quanjie-phase", 1)
        else
          for _, pid in ipairs(room:getOtherPlayers(p)) do
            room:damage({
              from = pid,
              to = p,
              damage = 1,
              damageType = fk.NormalDamage,
              skillName = skill.name,
            })
          end
          for _, pid2 in ipairs(room:getAlivePlayers()) do
            room:setPlayerMark(pid2, "@action__quanjie-phase", 0)
          end
          shouldBreak = 0
          break
        end
        if shouldBreak == 0 then break end
        if shouldBreak == 0 then return false end
      end
      if shouldBreak == 0 then break end
      if shouldBreak == 0 then return false end
    end
    if shouldBreak == 0 then return false end
  end,
})


skill:addEffect("filter", {
  mute = true,
  global = true,
  is_delay_effect = true,
  card_filter = function(self, card, player, isJudgeEvent)
    return card:getMark("action__quanjie-turn") == 1 and card and (table.contains(player.player_cards[Player.Hand], card.id) or isJudgeEvent)
    and card.name ~= "analeptic"
  end,
  view_as = function(self, player, to_select)
    return Fk:cloneCard("analeptic", to_select.suit, to_select.number)
  end,
})


return skill